//
//  ZWMainViewController.swift
//  ZWWeibo
//
//  Created by flyiron on 16/4/16.
//  Copyright © 2016年 flyiron. All rights reserved.
//

import UIKit


class ZWMainViewController: UITabBarController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        //compose按钮点击方法
        let tabbar = ZWTabBarView()
        tabbar.composeButtonClickClosure = {[weak self] in
            let composeVIew = ZWComposeView()
            composeVIew.show(self!)
            
        }
        self.setValue(tabbar, forKey: "tabBar")
        
        
        //添加子控制器
        addChildViewController(ZWHomeTableViewController(), title: "主页", imageName: "tabbar_home")
        addChildViewController(ZWMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(ZWDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ZWProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    func addChildViewController(vc: UIViewController , title: String , imageName: String ) {
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.title = title
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        addChildViewController(UINavigationController(rootViewController: vc))
        
    }
    
    private lazy var composeView:ZWComposeView = ZWComposeView()

}
